﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.BaseLibrary.ExceptionHandling;
using System.Data;

namespace Honestysoft.Financing.WebUI.Module.Project
{
    public partial class ProjectCompleteList : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                AspNetPager1.PageSize = Globals.PageSize;
                BindControl();
                Bind();
            }
        }
        /// <summary>
        /// 绑定页面控件。
        /// </summary>
        private void BindControl()
        {
            //btnAdd.Enabled = false;
            if (Request.QueryString["NodeType"] == ((int)Utils.ProjectTreeNodeType.Project).ToString())
            {
                txtProjectID.Text = Request.QueryString["NodeText"];
                txtProjectID.Enabled = false;
                //if (PageSecurity.Add)
                //{
                //    btnAdd.Enabled = true;
                //}
            }
        }
        /// <summary>
        /// 设置弹出窗体大小
        /// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
        protected override void SetDialogSize()
        {
            //base.SetDialogSize();
            //重载宽度，高度
            ModalDialogSize.EditHeight = 370;
            ModalDialogSize.EditWidth = 400;
            ModalDialogSize.ViewHeight = 370;
            ModalDialogSize.ViewWidth = 400;
        }
        /// <summary>
        /// 根据权限控制页面按钮.
        /// 基类中已自动做控制。
        /// </summary>
        protected override void ButtonSetting()
        {
            base.ButtonSetting();
            //使用PageSecurity检查权限
            //if (PageSecurity.Add)
            //{
            //    btnAdd.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Project/BD_ProjectAddInvestment_Edit.aspx?ProjectID=" + Request.QueryString["ID"] + "&FunctionID=" + FunctionID + "'," + ModalDialogSize.EditWidth + ", " + ModalDialogSize.EditHeight + ", '新增项目新增资本金');return false;");
            //}
        }

        protected string GetImages(string data)
        {
            string url = "<img src='"+ Globals.Home + "images/";
            if (data != "")
            {
                url = "-";
                //url += "accept2.gif' alt='有记录' />";
            }
            else
            {
                url += "delete2.gif' alt='没有记录' />";
            }
            return url;
        }

        /// <summary>
        /// 绑定列表
        /// </summary>
        private void Bind()
        {
            Honestysoft.Financing.BusinessLogic.Project bll = new BusinessLogic.Project(Globals.CurrentConnStringName);
            string projectId = "", projectName = "", projectCategory = "";
            if (Request.QueryString["NodeType"] == ((int)Utils.ProjectTreeNodeType.Project).ToString())
            {
                projectId = Request.QueryString["ID"];
            }
            else
            {
                if (Request.QueryString["NodeType"] == ((int)Utils.ProjectTreeNodeType.ProjectCategory).ToString())
                {
                    projectCategory = Request.QueryString["ID"];
                }
                if (txtProjectID.Text.Trim().Length > 0)
                {
                    projectName = txtProjectID.Text.Trim();
                }
            }
            int pageCount = 0, recordCount = 0;
            DataTable dtList = bll.GetProjectComplete(projectName, projectCategory, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out recordCount);
            AspNetPager1.RecordCount = recordCount;
            rptList.DataSource = dtList;
            rptList.DataBind();
        }
        /// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId)
        {
            string script = "";
            if (PageSecurity.View)
            {
                //if (script.Length > 0) { script += "&nbsp;"; }
                script = "<a href='ProjectCompleteInfo.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_self'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='审核项目信息' border='0' /></a>";
                //script += ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/ProjectCompleteInfo.aspx", "查看项目信息", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID);
            }
            return script;
        }

        protected string GetEditUrl(string text, string dataId)
        {
            string script = "";
            if (PageSecurity.View)
            {
                //if (script.Length > 0) { script += "&nbsp;"; }
                script = "<a href='ProjectCompleteInfo.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_self'>" + text + "</a>";
                //script += ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/ProjectCompleteInfo.aspx", "查看项目信息", ModalDialogSize.ViewWidth, ModalDialogSize.ViewHeight, dataId, FunctionID);
            }
            else
            {
                script = text;
            }
            return script;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Bind();
        }
        /// <summary>
        /// 得到选中的记录ID集合
        /// </summary>
        /// <returns></returns>
        private string[] GetSelectedRowKeys()
        {
            string strId = Request["chkID"] + "";
            if (string.IsNullOrEmpty(strId)) { return null; }
            return strId.Split(',');
        }

    }
}